package com.wl.cloud.security.component;

import com.wl.cloud.security.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: wanglin
 * @date: 2023-09-12 周二
 * @Version: 1.0
 * @Description: 当为登录或者token无效时访问接口，自定义返回结果
 */
@Slf4j
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request,
                         HttpServletResponse response,
                         AuthenticationException authException) throws IOException {
        SecurityUtils.resultFailMsg(response, HttpServletResponse.SC_UNAUTHORIZED, "未登录，请登录！", authException.getMessage());
    }
}
